<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use app\modules\Order\models\OrderCustomer;
use app\modules\Order\models\OrderPrice;
use kartik\editable\Editable;

$this->title = $model->product->name . '  ' . $model->product->go_time;
// 获取订单对应的人员信息
//$customer = OrderCustomer::find()->where(['order_id'=>$model->id, 'status'=>1])->all();
$customer = $model->customer;

//  获取订单附加费
$price = OrderPrice::find()->where(['order_id'=>$model->id, 'status'=>1])->all();

?>
<!-- ?=  yii\web\View::registerJsFile("/js/jquery.artZoom.js",['depends' => 'app\assets\AppAsset']) ? -->
<style type="text/css">
	.order-view font {color:#9E9A9A;margin-right:10px;}
	.for div {height: 40px;}
	.overflow {
		width: 100px;/*指定宽度*/
		height: 40px;
		float:left;
		display: inline-block;
	    word-break:keep-all;/* 不换行 */
	    white-space:nowrap;/* 强制在同一行内显示所有文本，直到文本结束或者遭遇 br 对象。不换行 */
		overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
		//text-overflow:ellipsis;/* IE 专有属性，当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用。*/
	}
	/* #w2-cont {width:125px;} */
	.k-remark .kv-editable {max-width: 90%;text-align:left;}
	.k-remark .kv-editable button {max-width: 840px;text-align:left;}
	.kv-editable-button {margin-top: -5px;}
	.popover {max-width: 1000px;}
</style>


<div class="order-view row" style="margin-left:0px;margin-right:0px;">

    <h2 class="page-header"><small><?= Html::encode($this->title) ?></small>
        <p class="pull-right">
			<?php if($model->status < 10){ 
            	echo Html::a('添加附加费', ['/order/price/create', 'order_id' => $model->id], ['class' => 'btn btn-primary', "data-toggle"=>"modal", "data-target"=>".customer-modal" ]); 
			} ?>

			<a class="btn btn-warning" data-toggle="modal" data-target=".room-modal" >添加舱房</a >

            <?= Html::a(Yii::t('app', '关联订单'), ['relation-order', 'id' => $model->id], ['class' => 'btn btn-info', "target"=>"_blank"]) ?>

			<?= ($model->status < 10)? Html::a('取消订单', ['/order/order/unrecovery', 'id' => $model->id], [
					'class' => 'btn btn-danger',
					'data' => [
						'confirm' => '确定取消该订单吗?',
						'method' => 'post',
					],
				]) : '<button class="btn btn-danger">已取消</button>'   
			?>

            <?= Html::a(Yii::t('app', 'Index'), ['index', 'product_id' => $model->product_id], ['class' => 'btn btn-success']) ?>

        </p>
    </h2>

	<div class="col-md-10 col-md-offset-1 panel panel-body">
    <div class="col-md-3 for"  style="padding:10px 0 0 0;">
        <div><font>舱房金额 :</font> <?= Yii::$app->formatter->asCurrency($model->total_sale) ?></div>
        <div>
			<font><?= ($model->check == 1 && $model->sale_price>0) ? '<i class="text-danger fa fa-check-circle"></i>' : '' ?>优惠额度:</font>
    		<?php echo Editable::widget([
    		    'name' => 'Order[sale_price]',
				'value' => $model->sale_price,
				'displayValue' => Yii::$app->formatter->asCurrency($model->sale_price),
    		    'asPopover' => true,
    		    'header' => '优惠金额',
    		    'size'=>'md',
    		    'formOptions' => ['action'=>'/order/order/edit-price?Order[id]='.$model->id,'method'=>'get'],
    		    'options' => ['class'=>'form-control', 'placeholder'=>'请输入优惠金额'],
    		    'pluginEvents'=> [
    		         "editableSuccess"=>"function(event, val, form, data) { 
    		             if(data){
    		                 $('#price').text(data.price); 
    		             }
    		         }",
    		    ],
    		]);
			//echo Yii::$app->formatter->asCurrency((int)$p1);
			?>
    		<?php echo Editable::widget([
    		    'name' => 'Order[price_desc]',
				'value' => $model->price_desc,
    		    'asPopover' => true,
    		    'header' => '优惠说明',
				'displayValue' => '<i class="fa fa-tags"></i>',
				'inputType' => Editable::INPUT_TEXTAREA,
    		    'size'=>'md',
    		    'formOptions' => ['action'=>'/order/order/edit-ajax?Order[id]='.$model->id,'method'=>'get'],
    		    'options' => ['class'=>'form-control',  'placeholder'=>'请输入优惠说明'],
    		]);?>
		</div>
        <div><font>附加费 :</font> <span><?= Yii::$app->formatter->asCurrency($model->priceSum) ?></span></div>
        <div>
			<font>总金额 :</font> <span id="price"><?= Yii::$app->formatter->asCurrency($model->price) ?></span> &nbsp; 
			<a class="fa fa-th-list" data-toggle="modal" data-target=".customer-modal"  href="/order/order/price-detail?id=<?= $model->id ?>" ></a> 
		</div>
    </div>

    <div class="col-md-3 for"  style="padding:10px 0 0 0;">
        <div><font>订单号 :</font> <?= $model->code ?></div>
        <div><font>来  源 :</font> <?= Yii::$app->params['order_source'][$model->source] ?></div>
        <div><font>销  售 :</font><?= isset($model->member->profile->name) ? $model->member->profile->name : '(未设置)' ?></div>
        <div><font>实  收 :</font> <?= Yii::$app->formatter->asCurrency($model->financeSuccess) ?>
		 <a class="fa fa-th-list" data-toggle="modal" data-target=".customer-modal"  href="/finance/finance/order-detail?order_id=<?= $model->id ?>" ></a>

		</div>
    </div>


    <div class="col-md-3  for" style="padding:10px 0px 0px 0px;" >
        <div><font>联系人 :</font> 
    		<?php echo Editable::widget([
    		    'name' => 'Order[username]',
				'value' => $model->username,
    		    'asPopover' => true,
    		    'header' => '联系人',
    		    'size'=>'md',
    		    'formOptions' => ['action'=>'/order/order/edit-ajax?Order[id]='.$model->id,'method'=>'get'],
    		    'options' => ['class'=>'form-control', 'placeholder'=>'请输联系人姓名'],
    		]);?>
		</div>

        <div><font>联系电话 :</font> 
    		<?php echo Editable::widget([
    		    'name' => 'Order[phone]',
				'value' => $model->phone,
    		    'asPopover' => true,
    		    'header' => '联系电话',
    		    'size'=>'md',
    		    'formOptions' => ['action'=>'/order/order/edit-ajax?Order[id]='.$model->id,'method'=>'get'],
    		    'options' => ['class'=>'form-control', 'placeholder'=>'请输联系电话'],
    		]);?>
		</div>
        <div><font>公司名称 :</font> 
    		<?php echo Editable::widget([
    		    'name' => 'Order[company]',
				'value' => $model->company,
    		    'asPopover' => true,
    		    'header' => '公司名称',
    		    'size'=>'md',
    		    'formOptions' => ['action'=>'/order/order/edit-ajax?Order[id]='.$model->id,'method'=>'get'],
    		    'options' => ['class'=>'form-control', 'placeholder'=> '公司名称'],
    		]);?>
		</div>

        <div><font>后返:</font> 
			<?= Yii::$app->formatter->asCurrency($model->commiss) ?>
    		<!-- </?php Editable::widget([
    		    'name' => 'Order[commiss_price]',
				'value' => $model->commiss_price,
				'displayValue' => Yii::$app->formatter->asCurrency($model->commiss_price),
    		    'asPopover' => true,
    		    'header' => '佣金金额',
    		    'size'=>'md',
    		    'formOptions' => ['action'=>'/order/order/commiss-ajax?Order[id]='.$model->id,'method'=>'get'],
    		    'options' => ['class'=>'form-control', 'placeholder'=> '佣金金额'],
    		]);?> -->
			<font><small>/上限: <?= $model->maxCommiss ?></small></font>
		</div>
    </div>

    <div class="col-md-3 for" style="padding:10px 0 0 0;">
        <div><font>创建时间 :</font> <?= Yii::$app->formatter->asDate($model->created_at)?></div>
        <div><font>更新时间 :</font><?= Yii::$app->formatter->asRelativeTime($model->updated_at)?></div>
        <div><font>状  态 :</font> 
			<?php if($model->status == 3){ ?>
				<?php 
				 $order_status = [4 => '确认提交'];
				 echo Editable::widget([
						'name'=>'Order[status]',
						'header' => '付款状态-----------------',
						'value' => Yii::$app->params['order_status'][$model->status],
						'formOptions' => ['action'=>'/order/order/edit-status?Order[id]='.$model->id,'method'=>'get'],
						'format' => Editable::FORMAT_BUTTON,
						'inputType' => Editable::INPUT_DROPDOWN_LIST,
						'data'=> $order_status, // [3=>'已付款'],
						'options' => ['class'=>'form-control'],
						'editableValueOptions' => ['class'=>'text-danger']
					]);
				 ?>
			<?php }else{ ?>
				<?= Yii::$app->params['order_status'][$model->status] ?>
			<?php } ?>
		</div>
    </div>

   	<div class="col-md-11 k-remark for " style="padding:0px 0px 0px 0; text-align:left;">
		<font>备 注 : </font>
    		<?php echo Editable::widget([
    		    'name' => 'Order[remark]',
				'value' => $model->remark,
    		    //'asPopover' => false,
    		    'header' => '备注信息',
				//'displayValue' => '<i class="fa fa-tags"></i>',
				'inputType' => Editable::INPUT_TEXTAREA,
    		    'formOptions' => ['action'=>'/order/order/edit-ajax?Order[id]='.$model->id,'method'=>'get'],
    		    'options' => ['class'=>'form-control', 'placeholder'=>'请输入备注信息', 'style'=>'width:540px;height:120px;'],
    		]);?>
	</div>
	</div>
	

	<?php if($price){ ?>
	<div class="col-md-10 col-md-offset-1 panel panel-body">
		<h4 class="page-header" style="margin-top:5px;margin-bottom:0px;"><small>附加费列表</small></h4>
		<div class="row">
			<?php foreach($price as $val){ ?>
				<!-- li class="list-group-item" style="height:45px;" -->
				<div class="row" style="margin: 20px 0 5px 0;">
					<div class="col-md-4"><?= $val->typeObj->name ?></div>
					<div class="col-md-2">单价: <?= Yii::$app->formatter->asCurrency($val->price) ?></div>
					<div class="col-md-2">人数: <?= $val->num ?> &nbsp; 人</div>
					<div class="col-md-2">总价: <?= Yii::$app->formatter->asCurrency($val->total_price) ?> </div>
					<div class="col-md-2 text-right">
				    <?php if($val->typeObj->type != 2){ ?>	
						<?php if($model->status < 10){ ?>
							<?= Html::a('<i class="fa fa-eye"></i>', ['/order/price/update', 'id' => $val->id],[
										'data-toggle' => "modal",
										'data-target' => ".customer-modal"  
									]) ?>
 							&nbsp;&nbsp;
							<?= Html::a('<i class="fa fa-remove"></i>', ['/order/price/delete', 'id' => $val->id], [
									'data' => [
										'confirm' => Yii::t('app', '确定删除该项附加费吗?'),
										'method' => 'post',
									],
								]) ?>
						<?php } ?>
					<?php }else{ ?>
						  <span style="color:red">必选附加费</span>
					<?php }?>
					</div>
				</div>
				<!-- /li -->
			<?php } ?>
		</div>
	</div>
	<?php } ?>

    <br>

    <!-- 舱房信息分配 -->
    <?php echo $this->render('room', ['model' => $model, 'customers'=>$customer]); ?>
</div>
